require("dotenv").config();
const express = require("express");
const cors = require("cors");
const path = require("path");
const apiLimiter = require("./middlewares/rateLimiter");
const loggerMiddleware = require("./middlewares/logger");
const transactionMiddleware = require("./middlewares/transaction");
// const { test } = require('./middlewares/redisHelper')

const app = express();
const port = process.env.PORT || 3000;

// 在原有中间件之后，路由之前添加
app.use(express.json());
app.use(cors());
app.use(apiLimiter);
app.use(loggerMiddleware);
// 新增事务中间件 ↓
app.use(transactionMiddleware());
// 新增事务中间件 ↑
app.use("/logs", express.static(path.join(__dirname, "./logs")));
app.use("/images", express.static(path.join(__dirname, "./images")));
app.use("/svg", express.static(path.join(__dirname, "./public/uploads")));

app.use("/api", require("./routes"));
// test()

app.listen(port, () => {
  console.log(`服务器正在端口 ${port} 上运行`);
});
